#include <unordered_map>
#include <vector>
using namespace std;

int majorityElement(vector<int> &nums) {
  int t = nums.size() / 2;
  unordered_map<int, int> elem_counter;
  for (int i = 0; i < nums.size(); ++i) {
    elem_counter[nums[i]]++;
    if (elem_counter[nums[i]] > t) {
      return nums[i];
    }
  }
  return 0;
}